package com.ithinkstudio.jeez.activiti7.config;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;

import com.fasterxml.jackson.databind.ObjectMapper;

public class AuthEntryPoint implements AuthenticationEntryPoint {

	public static ObjectMapper objectMapper = new ObjectMapper();

	@Override
	public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
			AuthenticationException e) throws IOException, ServletException {
		httpServletResponse.setContentType("application/json;charset=UTF-8");
		BaseResponse<Void> response = new BaseResponse<>(401, "请先登录系统");
		httpServletResponse.getWriter().write(objectMapper.writeValueAsString(response));
	}
	
}
